package com.product.controller;

import com.product.result.ApiResult;
import com.product.service.IOperationLogService;
import com.product.utils.PageUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "操作日志控制器")
@RestController
@RequestMapping("/operationlog")
public class OperationLogController {
    @Autowired
    private IOperationLogService operatorService;

    @Parameters({
            @Parameter(name = "size", description = "每页条数，默认10条"),
            @Parameter(name = "current", description = "分页页数，默认第一页"),
            @Parameter(name = "OperatorId", description = "用户Id"),
            @Parameter(name = "operatorType", description = "操作类型，0-->修改操作，1-->新增操作，2-->删除操作"),
            @Parameter(name = "timeOrderBy", description = "按照操作时间顺序排序,0->升序,1->降序"),
            @Parameter(name = "token", description = "用户token,放到请求头的Authorization属性")
    })
    @Operation(summary = "获取所有操作日志")
    @GetMapping("/all")
    private ApiResult<PageUtils> getAllOperators(@RequestParam(name = "size", defaultValue = "10") Integer size,
                                             @RequestParam(name = "current", defaultValue = "1") Integer current,
                                             @RequestParam(name = "OperatorId", required = false) Integer OperatorId,
                                             @RequestParam(name = "operatorType", required = false) Integer operatorType,
                                             @RequestParam(name = "timeOrderBy", defaultValue = "1") Integer timeOrderBy) {
        return ApiResult.ok(operatorService.getAllOperator(size, current, OperatorId, operatorType, timeOrderBy));
    }

    @Parameters({
            @Parameter(name = "operatorId", description = "操作日志id"),
            @Parameter(name = "token", description = "用户token,放到请求头的Authorization属性")
    })
    @Operation(summary = "删除操作日志")
    @PostMapping("/delete")
    private ApiResult<Boolean> deleteOperator(@RequestParam(name = "operatorId") Integer operatorId) {
        operatorService.deleteOperator(operatorId);
        return ApiResult.ok();
    }

    @Parameter(name = "token", description = "用户token,放到请求头的Authorization属性")
    @Operation(summary = "批量删除操作日志")
    @PostMapping("/deletes")
    private ApiResult<Boolean> deleteOperators(@RequestBody List<Integer> operatorIds) {
        operatorService.deleteOperators(operatorIds);
        return ApiResult.ok();
    }
}
